import Vue from "vue";
import Vuex from 'vuex';

Vue.use(Vuex);

export default new Vuex.Store({
    state: {
        todoDatas:[
            {
              id:1,
              todoName: '123',
              isDone: false
            }
        ]
    },
    actions: {},
    mutations: {
        pushTodoDatas(state,value){
            state.todoDatas.push({id:Date.now(),todoName:value,isDone:false});
            console.log(state);
          },
          changeIsDone(state,id){
            state.todoDatas.find((item) => {
              item.id == id ? item.isDone = !item.isDone : '';
            })
          },
          changeAllIsDone(state,isAllDone){
            state.todoDatas.forEach((item) => {
              item.isDone = isAllDone;
            })
          },
          removeItem(state,id){
            state.todoDatas = state.todoDatas.filter((item) => {
              return item.id != id;
            })
          },
          removeIsDoneTodos(state){
            state.todoDatas = state.todoDatas.filter((item) => {
              return item.isDone != true;
            })
          }
    }
})